package multitester.testers;

import multitester.annonations.ImportedTest;

import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Yuriy Sechko
 */
public class MultiTester
{
	public MultiTester(final Class configuration)
	{
		if (configuration == null)
		{
			throw new IllegalArgumentException(
					"Configuration class should not be null.");
		}
		final Annotation implementationTestAnnotation = configuration
				.getAnnotation(ImportedTest.class);
		if (implementationTestAnnotation == null)
		{
			throw new IllegalArgumentException(
					"Given configuration class does not contain 'ImplementationTest' annotation.");
		}
		final ImportedTest actualConfig = (ImportedTest) implementationTestAnnotation;
		for (final String currentAlias : actualConfig.startupSequence())
		{

			if ("".equals(currentAlias))
			{
				throw new IllegalArgumentException(
						"Empty aliases are not allowed in startup sequence.");
			}
		}
		for (final String currentAlias : actualConfig.shutdownSequence())
		{

			if ("".equals(currentAlias))
			{
				throw new IllegalArgumentException(
						"Empty aliases are not allowed in shutdown sequence.");
			}
		}
		final Set<String> startupSequenceAliases = new HashSet<String>();
		for (final String currentAlias : actualConfig.startupSequence())
		{
			if (startupSequenceAliases.contains(currentAlias))
				throw new IllegalArgumentException(
						"Duplicated aliases are not allowed in startup sequence.");
			startupSequenceAliases.add(currentAlias);
		}
		final Set<String> shutdownSequenceAliases = new HashSet<String>();
		for (final String currentAlias : actualConfig.shutdownSequence())
		{
			if (shutdownSequenceAliases.contains(currentAlias))
				throw new IllegalArgumentException(
						"Duplicated aliases are not allowed in shutdown sequence.");
			shutdownSequenceAliases.add(currentAlias);
		}
	}

	public void startup()
	{

	}
}
